package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/loginStudentServlet")
public class loginStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        获取提交来的参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");
//        判断用户名
        if(username==null||"".equals(username)){
//            用户名为空时候,重定向到登录页面
            resp.sendRedirect("/dididi/login.jsp");
            return;
        }
//        用户名不为空时候,将用户名存入到回话域中
        req.getSession().setAttribute("username",username);
//       重定向到首页index.jsp
        resp.sendRedirect("/dididi/index.jsp");
    }
}
